#ifndef CORE_UTIL_CLASS
#define CORE_UTIL_CLASS

#include <string>
#include <fstream>
#include <sstream>
#include <sys/types.h>
#include <sys/socket.h>
#include <cstdlib>
#include <netinet/in.h>
#include <errno.h>
#include <cstring>
#include <unistd.h>

namespace pland
{

/*! Check if file exists.
 * \param path pathname to the file in question.
 * \return true if file exists, false otherwise.
 * */
bool util_fexists(std::string path);

/*! Log a message.
 * \param message message to log.
 */
void utill_log(std::string message);

/*! Set logging to the selected stream.
 * \param out output stream.
 * \return true on success, false on failier.
 */
bool utill_set_log(std::ostream *out);

/*! Flush the log file.
 */
void utill_flush_log();


ssize_t utill_io_read(int fd, char* buff, size_t len);

ssize_t utill_io_write(int fd, char* buff, size_t len);

/*!
 * Convert generic type to string
 */
template <class T> inline std::string utill_to_string (const T& t)
{
    std::stringstream ss;
    ss << t;
    return ss.str();
}


/*!
 * Convert generic type to int
 */
template <class T> inline int utill_to_int (const T& t)
{
    int out;
    std::stringstream ss(t);
    ss >> out;
    return out;
}

/*!
 * Convert generic type to float
 */
template <class T> inline float utill_to_float (const T& t)
{
    float out;
    std::stringstream ss(t);
    ss >> out;
    return out;
}

}
#endif /*coreutil.hpp*/
